package com.yunhe.tianhe.rentcars.controller.client;/**
 * Created by Administrator on 2017/11/30 0030.
 */

import com.yunhe.tianhe.commons.dto.Pageable;
import com.yunhe.tianhe.rentcars.dto.JSONResponse;
import com.yunhe.tianhe.rentcars.entity.client.Client;
import com.yunhe.tianhe.rentcars.entity.client.Credit;
import com.yunhe.tianhe.rentcars.service.client.ClientService;
import com.yunhe.tianhe.rentcars.service.client.CreditRecordService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @user yanxiu
 * @creat 2017-11-30 下午 12:18
 * @desc
 **/
@Controller
@RequestMapping("/credit")
public class CreditRecordController {

    @Autowired
    private CreditRecordService creditRecordService;
    @Autowired
    private ClientService clientService;

    @RequestMapping
    public  String list(){
        return "client/credit/credit";
    }

    @RequestMapping("/listData")
    @ResponseBody
    Pageable<Credit> findPage(Integer offset, Integer limit, String name, String mobile, String idCard){
        Pageable<Credit> page = creditRecordService.findPage(offset, limit, name, mobile, idCard);
        return page;
    }

    @RequestMapping("/add")
    public String add(){
        return "client/credit/add";
    }

    //在添加页上展示客户信息
    @RequestMapping("/clientData")
    @ResponseBody
    public JSONResponse client(String mobile){
        JSONResponse success=null;
        Client client = clientService.findOneByMobile(mobile);
        if(null!=client){
            success = JSONResponse.success("请核对客户信息！", client);
        }else{
            success = JSONResponse.fail("无此客户，请核查手机号！");
        }
        return success;
    }

    @RequestMapping("/saveAjax")
    @ResponseBody
    public JSONResponse save(Credit credit, String mobile){
        creditRecordService.save(credit,mobile);
        return JSONResponse.success("添加成功");
    }

    @RequestMapping("/pan")
    public String pan(){
        return "client/credit/pan";
    }

}
